﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
using Pixysoft.Tools;
using Pixysoft.Threads;
using System.Data;

namespace Pixysoft.Framework.Noebe.testdriven
{
    class tc_002
    {
        public static void createstructure()
        {
            NoebeConfiguration from = new NoebeConfiguration();
            from.DatabaseType = Pixysoft.Framework.XSchEmA.DatabaseType.Access;
            from.Filename = @"XXX";


            NoebeConfiguration to = new NoebeConfiguration();
            to.DatabaseType = Pixysoft.Framework.XSchEmA.DatabaseType.SqlServer;
            to.ServerName = "XXX";
            to.DatabaseName = "XXX";
            to.UserName = "XXX";
            to.Password = "XXX";
            Console.WriteLine(to.ConnectionString);

            NoebeManager.Tools.Cloner.StructClone(from, to);
        }

        public static void testmysql()
        {
            NoebeConfiguration info = new NoebeConfiguration();
            info.DatabaseType = Pixysoft.Framework.XSchEmA.DatabaseType.MySql;
            info.DatabaseName = "XXX";
            info.UserName = "XXX";
            info.Password = "XXX";
            NoebeManager.Reload(info);
        }

        public static void test()
        {
            Console.WriteLine(Pixysoft.IO.XmlExporter.Instance.XmlSerialize(new NoebeKeyValuePair<string, DotNetDataType>("12", DotNetDataType.Boolean)));
        }

        public static void testMYSQL()
        {
            //Time Elapsed:		8,125ms
            //CPU time:		0ns
            //Gen 0: 			41
            //Gen 1: 			8
            //Gen 2: 			1

            NoebeConfiguration info = new NoebeConfiguration();
            info.DatabaseType = Pixysoft.Framework.XSchEmA.DatabaseType.MySql;
            info.DatabaseName = "XXX";
            info.UserName = "XXX";
            info.Password = "XXX";
            info.IsConnectionPoolEnabled = true;
            NoebeManager.Reload(info);

            CodeTimer.Initialize();

            CodeTimer.Time("test", 5, delegate()
            {
                MapReduceInvoker helper = new MapReduceInvoker();
                for (int i = 0; i < 100; i++)
                    helper.Invokes(new tc_002().run);
                helper.Waits();
                Console.WriteLine("done.");
            });

            Console.WriteLine(NoebeManager.Instance.GetSnapshot().ToString());
        }

        public void run()
        {
            DataTable table = NoebeManager.Instance.GetEntity("tc_manualpk");
            for (int i = 0; i < 100; i++)
            {
                DataRow row = table.NewRow();
                row["COL_VARCHAR1"] = "测试中文";
                row["COL_VARCHAR2"] = "测试中文";
                row["COL_VARCHAR3"] = "测试中文";
                row["COL_VARCHAR4"] = "测试中文";
                row["COL_DATETIME1"] = DateTime.Now;
                row["COL_DATETIME2"] = DateTime.Now;
                row["COL_INT1"] = 1;
                row["COL_INT2"] = 1;
                row["COL_DOUBLE1"] = 1.1;
                row["COL_DOUBLE2"] = 1.1;
                row["COL_BLOB"] = new byte[] { 1, 2, 3 };
                row["COL_INDEX"] = "测试中文";
                NoebeManager.Instance.Session.AutoInsert(row);
            }
            Console.WriteLine("finish insert.");
        }
    }
}
